<?php

// +----------------------------------------------------------------------
// | 版权所有 2017-2027 云南环拓科技有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.yn123.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// | 注意：  这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用,
// |        不允许对程序代码以任何形式任何目的的再发布。
// +----------------------------------------------------------------------
// | Author: feraner <feraner@163.com> 
// | Date: 2019/12/9
// +----------------------------------------------------------------------

namespace app\common\services;

use Carbon\Carbon;
use think\Db;

/**
 * 广告类
 * Class AdvertService
 * @package app\common\services
 * @author feraner<feraner@163.com>
 * @date 2019/12/9
 */
class AdvertService
{

    public function __construct()
    {

    }


    /**
     * 获取广告详细列表
     * @param $locationId
     *
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getAdvertList($locationId)
    {
        $bannerList = Db::name('web_banner')->alias('wb')
            ->where('wb.tid', $locationId)
            ->where('wb.status', 1)
            ->join('web_banner_type wbt', 'wb.tid = wbt.id')
            ->where('wbt.status', 1)
            ->where('wb.start_time', '<=', Carbon::today()->getTimestamp())
            ->where('wb.end_time', '>=', Carbon::today()->getTimestamp())
            ->field('wb.*, wbt.title as locationTitle')
            ->order('wb.sort ASC')
            ->select() ?: [];

        return $bannerList;
    }


}
